﻿' Copyright (C) 2015 HTTPBuilder
'
' This program is free software: you can redistribute it and/or modify it under the +terms 
' of the GNU General Public License as published by the Free Software Foundation, either 
' version 3 of the License, or (at your option) any later version.

' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
' without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
' See the GNU General Public License for more details.

' You should have received a copy of the GNU General Public License along with this program.
' If not, see http://www.gnu.org/licenses/. 

Imports Microsoft.Win32

Public Class Settings

    Public Shared ReadOnly Property DefaultUrl As String
        Get
            Return GetValue("defaulturl", "http://www.microsoft.com")
        End Get
    End Property
    Public Shared Property Wordwrap As Boolean
        Get
            Return GetValue("wordwrap", False)
        End Get
        Set(value As Boolean)
            SetValue("wordwrap", value)
        End Set
    End Property
    Public Shared Property FocusResponseBody As Boolean
        Get
            Return GetValue("focusresponsebody", False)
        End Get
        Set(value As Boolean)
            SetValue("focusresponsebody", value)
        End Set
    End Property

    Private Shared Sub SetValue(key As String, value As Object)
        Dim rkey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\HttpBuilder", True)
        If rkey Is Nothing Then
            rkey = Registry.CurrentUser.CreateSubKey("Software\HttpBuilder")
        End If
        rkey.SetValue(key, value)
    End Sub

    Private Shared Function GetValue(key As String, defaultValue As Object) As Object
        Dim rkey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\HttpBuilder", False)
        If rkey Is Nothing Then
            Return defaultValue
        End If

        Return rkey.GetValue(key, defaultValue)
    End Function
End Class
